package it.unipd.dei.project.iandroid;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

public class FotoAdapter extends ArrayAdapter<Foto> {
	// we keep track of model objects in a local variable for our convenience
	private ArrayList<Foto> items;
	private Context context;

	public FotoAdapter(Context context, int textViewResourceId, ArrayList<Foto> items) {
		super(context, textViewResourceId, items);
		this.context = context;
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// performance issue (see Google I/O video in references)
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.foto, null);
		}
		// position contains the index of the array for
		// the associated item so we retrieve the Contact
		Foto c = this.items.get(position);
		if (c != null) {
			ImageView picImageView = (ImageView) v.findViewById(R.id.foto);
			picImageView.setImageBitmap(c.getIcon());
		}
		return v;
	}

}